package com.iOS.service.impl;

import com.iOS.dao.PushInfoMapper;
import com.iOS.dto.PushInfoExecution;
import com.iOS.entity.PushInfo;
import com.iOS.enums.PushInfoEnum;
import com.iOS.service.IPushInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PushInfoServiceImpl implements IPushInfoService{
    @Autowired
    private PushInfoMapper pushInfoMapper;

    @Override
    public PushInfoExecution Add(PushInfo push) {
        try {
            PushInfo pushInfo = new PushInfo();
            pushInfo.setUserId(push.getUserId());
            pushInfo.setPushTitle(push.getPushTitle());
            pushInfo.setPushContext(push.getPushContext());
            pushInfo.setPushPictures(push.getPushPictures());
            pushInfo.setCreateTime(new Date());

            pushInfoMapper.insert(pushInfo);
            return new PushInfoExecution(PushInfoEnum.SUCCESS);
        } catch (Exception e) {
            return new PushInfoExecution(PushInfoEnum.FAIL);
        }
    }

    @Override
    public void Delete(int id) {
        pushInfoMapper.delete(id);
    }

    @Override
    public List<PushInfo> getPushList() {
        return pushInfoMapper.queryAll(0, 100);
    }

    @Override
    public PushInfo getById(int id) {
        return pushInfoMapper.queryById(id);
    }

}
